import api from '../../api';
import { message } from 'antd';
import uuid from 'es6-uuid';

export default {
  namespace: 'myAttentionM',

  state: {},

  effects: {
    //获取个券组列表
    *getBondGroupList({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.getBondGroupList, payload);
      if (res && res.code == 0) {
        callback(res);
      } else {
        message.error(res.message);
      }
    },

    //获取主体组列表
    *getMainGroupList({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.getMainGroupList, payload);
      if (res && res.code == 0) {
        callback(res);
      } else {
        message.error(res.message);
      }
    },

    //新增个券组/主体组
    *addGroup({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.addGroup, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res.message);
      }
    },

    //编辑个券组/主体组
    *editGroup({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.editGroup, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    //删除个券组/主体组
    *deleteGroup({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.deleteGroup, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    //获取个券详情列表
    *getBondInfoList({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.getBondInfoList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    //获取主体详情列表
    *getMainInfoList({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.getMainInfoList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    //新增关注--个券
    *addBondAttention({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.addBondAttention, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    //新增关注--主体
    *addMainAttention({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.addMainAttention, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    //删除（取消关注）个券/主体
    *deleteAttention({ payload, callback }, { call, put }) {
      const res = yield call(api.myAttention.deleteAttention, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },

    // 获取主体全程(发行人)下拉列表
    *getIssuerList({ payload, callback }, { call, put }) {
      const res = yield call(api.getIssuerList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.message);
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
